package com.expoente.view;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.expoente.model.LineInformation;
import com.expoente.model.Place;

public class LineReviewActivity
		extends Activity {
	
	LineInformation lineInformation;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.line_review_activity);

		TextView lineDetails = (TextView) findViewById(R.id.lineDetails);
		TextView lineName = (TextView) findViewById(R.id.lineName);
		TextView lineCost = (TextView) findViewById(R.id.lineCost);

		Intent intent = getIntent();
		lineInformation = (LineInformation) intent
				.getSerializableExtra("item");

		lineDetails.setText(this.getString(R.string.lineDetails));
		lineName.setText(this.getString(R.string.lineName)
				+ this.getString(R.string.twoDots)
				+ lineInformation.getLine().getName());

		NumberFormat nf = NumberFormat.getCurrencyInstance();
		nf.setMinimumFractionDigits(2);

		String cost = nf.format(lineInformation.getLine().getCost());
		lineCost.setText(this.getString(R.string.lineCost)
				+ this.getString(R.string.twoDots)
				+ this.getString(R.string.currencyCode) + cost);

		List<String> listPlaces = new ArrayList<String>();
		for (Place place : lineInformation.getPlaces()) {
			listPlaces.add(place.getAddress());
		}

		ListView listView = (ListView) findViewById(R.id.listView);
		ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this,
				R.layout.list_item, listPlaces);
		listView.setAdapter(listAdapter);
		
		Button showLineInMapButton = (Button) findViewById(R.id.showLineInMapButton);
		showLineInMapButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View view) {
				Intent intent = new Intent(view.getContext(), GoogleMapsActivity.class);
				intent.putExtra("item", lineInformation);
				startActivity(intent);
			}
		});
	}

}
